<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport"
        content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
    <link rel="stylesheet" type="text/css" href="../css/aui-flex.css" />
    <style>
    </style>
</head>
<style>
    .home:before {
        content: url(../image/home.png);
    }

    .refresh:before {
        content: url(../image/refresh.png);
    }

    .company:before {
        content: url(../image/company.png);
    }

    .pa-title {
        font-size: 17px;
        color: black;
        font-weight: bold;
    }

    .pa-title-content {
        font-size: 17px;
        color: black;
    }

    body {
        background-color: #D9D8DB;
    }

    .pa_sglg_t {
        background-color: #254060;
        height: 377px;
        color: white;
        overflow: auto;
    }

    .pa_sglg_but {
        height: 58px;
        line-height: 58px;
        float: left;
        width: 90px;
        font-size: 20px;
        color: white;
        text-align: center;
    }

    .pa_sglgProd {
        font-size: 15px;
        float: left;
        height: 58px;
        line-height: 58px;
        text-align: center;
        margin-left: 5px;
    }

    p {
        font-size: 17px;
        color: black;
        font-weight: bold;
        text-align: center;
    }

    table {
        width: 100%;
        table-layout: fixed;
        word-wrap: break-word;
    }

    td {
        white-space: nowrap;
        text-overflow: ellipsis;
        overflow: hidden;
    }
</style>

<body>
    <header class="aui-bar aui-bar-nav" style="background-color: #D9D8DB">
        <div style="width: 10%;height: 60px;float: left;padding-top: 6px;">
            <a class="aui-pull-left aui-btn ">
                <span class="aui-iconfont company"></span>
            </a>
        </div>
        <div style="width: 10%;height: 60px;float: left;">
            <div style="text-align: left;">
                <span class="pa-title">富晟安创</span>
            </div>
        </div>
        <div style="width: 70%;height: 60px;float: left;">
            <div style="width:18%; float: left; text-align: left;">
                <span class="pa-title-content" id="locationName"></span>
            </div>
            <div style="width:18%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCenterName"></span>
            </div>
            <div style="width:24%; float: left; text-align: left;">
                <span class="pa-title-content" id="workCellName"></span>
            </div>
            <div style="width:40%; float: left; text-align: left;">
                <span class="pa-title-content" id="nowDate"></span>
            </div>
        </div>
        <div style="width: 5%;height: 50px;float: left;">
            <a class="aui-pull-right aui-btn " onclick="refresh()">
                <span class="aui-iconfont refresh"></span>
            </a>
        </div>
        <div style="width: 5%;height: 50px;float: left;">
            <a class="aui-pull-right aui-btn" onclick="closeWin()">
                <span class="aui-iconfont home"></span>
            </a>
        </div>
    </header>
    <div class="aui-content">
        <div class="aui-flex-col aui-flex-center" style="height: 30px;">
            <div class="aui-flex-item-12">
                <p>产线人员上岗</p>
            </div>
        </div>
        <div class="aui-flex-col aui-flex-center">
            <div class="aui-flex-item-12">
                <div class="aui-flex-item-3">
                    <div class="aui-flex-col">
                        <div class="aui-flex-item-12">
                            <div class="aui-list-item-inner" style="background-color: #D9D8DB; border: 0;">
                                <div class="aui-list-item-label pa_sglgProd"> 生产日期：</div>
                                <div class="aui-list-item-input"
                                    style="background-color: white;float: left;width: 130px;"
                                    onclick="timePicker('prodDate');">
                                    <input type="text" placeholder="选择日期" class="aui-input" id="prodDate">
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="aui-flex-item-3">
                    <div class="aui-flex-col">
                        <div class="aui-flex-item-12">
                            <ul class="aui-list aui-form-list">
                                <li class="aui-list-item" style="background-color: #D9D8DB; border: 0;">
                                    <div class="aui-list-item-inner" style="background-color: #D9D8DB; border: 0;">
                                        <div class="aui-list-item-label" style="font-size: 15px;">班次：</div>
                                        <div class="aui-list-item-input" style="background-color: white;">
                                            <select id="shiftCode" onchange="searchTakePostData()">
                                            </select>
                                        </div>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>

                <div class="aui-flex-item-3">
                    <div class="aui-flex-col">
                        <div class="aui-flex-item-12">
                            <ul class="aui-list aui-form-list">
                                <li class="aui-list-item" style="background-color: #D9D8DB; border: 0;">
                                    <div class="aui-list-item-inner" style="background-color: #D9D8DB; border: 0;">
                                        <div class="aui-list-item-label" style="font-size: 15px;">班组：</div>
                                        <div class="aui-list-item-input" style="background-color: white;">
                                            <select id="teamCode" onchange="searchTakePostData()">
                                            </select>
                                        </div>
                                    </div>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>

                <div class="aui-flex-item-3">
                    <div class="aui-flex-col ">
                        <div class="aui-flex-item-12">

                            <div class="pa_sglg_but" style="background-color: green;margin-left:15px;"
                                onclick="takeQuittPostClick(1)">上岗
                            </div>
                            <div class="pa_sglg_but" style="background-color: red;margin-left:10px;"
                                onclick="takeQuittPostClick(2)">
                                离岗
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="aui-flex-col aui-flex-center" style="margin-top: 1%;">
            <div class="aui-flex-item-12">
                <div class="aui-flex-col pa_sglg_t">
                    <div class="aui-flex-item-12">
                        <div style="height: 100%;width: 100%;">
                            <table class="table" border="1px solid gray" cellspacing="0" cellpadding="0">
                                <thead>
                                    <tr style="text-align: center;color: white;font-size: 20px;">
                                        <td algin='center' style="width:5%">序号</td>
                                        <td algin='center' style="width:12%">姓名</td>
                                        <td algin='center' style="width:12%">工号</td>
                                        <td algin='center' style="width:13%">生产日期</td>
                                        <td algin='center' style="width:10%">班次</td>
                                        <td algin='center' style="width:12%">班组</td>
                                        <td algin='center' style="width:18%">上岗时间</td>
                                        <td algin='center' style="width:18%">离岗时间</td>
                                    </tr>
                                </thead>
                                <tbody id="takeQuitPostDataHtml">
                                </tbody>
                            </table>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript">

    var equipUniqueId = "";

    //初始化
    apiready = function () {
        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');
        //产线工位信息
        document.getElementById("locationName").innerHTML = api.pageParam.locationName;
        document.getElementById("workCenterName").innerHTML = api.pageParam.workCenterName;
        document.getElementById("workCellName").innerHTML = api.pageParam.workCellName;
        document.getElementById("nowDate").innerHTML = getTimeCommon();
        //当前时间刷新
        window.setInterval("getTime()", 1000);

        //1:初始化当前日期
        crateDate();

        //2:查询班组班次下拉框
        doSearchTeamShift();

    }

    //时间刷新
    function getTime() {
        document.getElementById("nowDate").innerHTML = getTimeCommon();
    }

    //获取当前日期
    function crateDate() {
        if (api.pageParam.proddate == null || api.pageParam.proddate == "" || api.pageParam.proddate == undefined) {
            var date = new Date();
            var year = date.getFullYear();
            var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
            var day = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
            $("#prodDate").val(year + "-" + month + "-" + day);
        } else {
            $("#prodDate").val(api.pageParam.proddate);
        }
    }

    //时间选择器
    function timePicker(id) {
        api.openPicker({
            type: 'date',
            date: new Date(),
            title: '选择日期'
        }, function (ret, err) {
            if (ret) {
                var monthTemp = (ret.month < 10 ? '0' + ret.month : ret.month);
                var dayTemp = (ret.day < 10 ? '0' + ret.day : ret.day);
                var date = ret.year + "-" + monthTemp + "-" + dayTemp;
                $("#" + id).val(date);

                //查询表格数据
                searchTakePostData();
            }
        });
    }

    //班组下拉框
    function doSearchTeamShift() {
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyTeam";
        var data = {
            values: {
                workCenterCode: api.pageParam.workCenterCode,
                clientCode: equipUniqueId,
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == 0) {

                    //班組賦值
                    var list = eval(myobj.list);
                    var html = "<option value=''>--请选择--</option>";
                    for (var i = 0; i < list.length; i++) {
                        html += "<option value='" + list[i].code + "'>" + list[i].name + "</option>";
                    }
                    $api.html($api.byId("teamCode"), html);
                    $("#teamCode").val(api.pageParam.teamCode);

                    //班次赋值
                    var listShift = eval(myobj.listShift);
                    var htmlShift = "<option value=''>--请选择--</option>";
                    for (var i = 0; i < listShift.length; i++) {
                        htmlShift += "<option value='" + listShift[i].code + "'>" + listShift[i].name + "</option>";
                    }
                    $api.html($api.byId("shiftCode"), htmlShift);
                    $("#shiftCode").val(api.pageParam.shiftCode);

                    //传输参数日期班组班次不为空，查询数据
                    if (api.pageParam.teamCode != null && api.pageParam.teamCode != "" && api.pageParam.teamCode != undefined) {
                        searchTakePostData();
                    }
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //查询上岗信息
    function searchTakePostData() {
        var workCellCode = "";
        //是否按工位上岗查询：0否，1是
        var cjFlag = api.pageParam.cjFlag;
        if ("1" == cjFlag) {
            workCellCode = api.pageParam.workCellCode;
        }
        var proddate = $("#prodDate").val();
        var teamCode = $("#teamCode").val();
        var shiftCode = $("#shiftCode").val();
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyTakePostData";
        var data = {
            values: {
                workCenterCode: api.pageParam.workCenterCode,
                workCellCode: workCellCode,
                proddate: proddate,
                teamCode: teamCode,
                shiftCode: shiftCode,
                un: un,
            }
        };
        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //成功
                if (myobj.code == 0) {

                    //班組賦值
                    var list = eval(myobj.list);
                    var html = "";
                    //遍历
                    for (var i = 0; i < list.length; i++) {
                        html += "<tr style='text-align: center;color: white;font-size: 14px;height:50px;'>";
                        html += "<td name='index'>" + (i + 1) + "</td>";
                        html += "<td name='empName'>" + list[i].empName + "</td>";
                        html += "<td name='empNo'>" + list[i].empNo + "</td>";
                        html += "<td name='proddate'>" + list[i].proddate + "</td>";
                        html += "<td name='shiftName'>" + list[i].shiftName + "</td>";
                        html += "<td name='teamName'>" + list[i].teamName + "</td>";
                        html += "<td name='startWorkTime'>" + list[i].startWorkTime + "</td>";
                        if (list[i].endWorkTime == null || list[i].endWorkTime == undefined) {
                            html += "<td name='endWorkTime'></td>";
                        } else {
                            html += "<td name='endWorkTime'>" + list[i].endWorkTime + "</td>";
                        }
                        html += "</tr>";
                    }

                    $api.html($api.byId("takeQuitPostDataHtml"), html);
                } else {
                    $api.html($api.byId("takeQuitPostDataHtml"), "");
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                alert("网络连接超时!")
            }
        });
    }

    //上岗/离岗
    function takeQuittPostClick(flag) {
        var proddate = $("#prodDate").val();
        var teamCode = $("#teamCode").val();
        var shiftCode = $("#shiftCode").val();
        if (proddate == null || proddate == "" || proddate == undefined) {
            api.toast({
                msg: "请选择生产日期!",
                duration: 3000
            });
            return;
        }

        if (teamCode == null || teamCode == "" || teamCode == undefined) {
            api.toast({
                msg: "请选择班组!",
                duration: 3000
            });
            return;
        }

        if (shiftCode == null || shiftCode == "" || shiftCode == undefined) {
            api.toast({
                msg: "请选择班次!",
                duration: 3000
            });
            return;
        }

        //上岗标识：0刷卡，1勾选
        var sgFlag = api.pageParam.sgFlag;

        //刷卡
        if ("0" == sgFlag) {

            swipeCard(flag);

            //勾选
        } else {
            var pageParam = api.pageParam;
            pageParam.flag = flag;
            pageParam.proddate = proddate;
            pageParam.shiftCode = shiftCode;
            pageParam.teamCode = teamCode;
            api.openWin({
                name: "productionAssemblySglg_select",
                url: 'productionAssemblySglg_select.html',
                pageParam: pageParam,
            });
        }
    }

    //刷卡
    function swipeCard(flag) {
        var title = "";
        if (flag == 1) {
            title = "上岗";
        } else if (flag == 2) {
            title = "离岗";
        }
        var dialogBox = api.require('dialogBox');
        dialogBox.input({
            keyboardType: 'default',
            texts: {
                title: title,
                placeholder: '扫描/录入卡号',
                leftBtnTitle: '取消',
                rightBtnTitle: '确定'
            },
            styles: {
                bg: '#fff',
                corner: 2,
                w: 300,
                h: 240,
                title: {
                    h: 60,
                    alignment: 'center',
                    size: 14,
                    color: '#000',
                    marginT: 30,
                },
                input: {
                    h: 60,
                    y: 30,
                    marginT: 15,
                    marginLeft: 10,
                    marginRight: 10,
                    textSize: 20,
                    textColor: '#000',
                    corner: 5,                  //（可选项）数字类型；对输入框圆角大小；默认：0

                },
                dividingLine: {
                    width: 0.5,
                    color: '#696969'
                },
                left: {
                    bg: 'rgba(0,0,0,0)',
                    color: '#007FFF',
                    size: 12,
                    h: 40,                //(可选项) 数字类型；右边按钮的高度；默认：40
                    w: 60,                   //(可选项) 数字类型；左边按钮的宽度；默认：提示框的宽度的一半
                    marginB: 10,            //(可选项) 数字类型；左边按离底部的边距；默认：0
                    corner: 5,              //(可选项) 数字类型；左边按钮的圆角；默认：0
                    widhtBorder: 1,         //(可选项) 数字类型；左边按钮的边宽；默认：0
                    normalBorderColor: '#778899', //(可选项) 数字类型；左边按钮的边宽颜色；默认：'rgba(0,0,0,0)'
                    activeBorderColor: '#0000CD', //(可选项) 数字类型；左边按钮的高亮状态下边宽颜色；默认：'rgba(0,0,0,0)'
                    activeColor: '#006400', //(可选项) 数字类型；左边按钮的高亮状态下标题颜色；默认：'rgba(0,0,0,0)'
                    activeBg: '#6B8E23'   //(可选项) 数字类型；左边按钮的高亮状态下背景颜色；默认：'rgba(0,0,0,0)'
                },
                right: {
                    bg: 'rgba(0,0,0,0)',
                    color: '#007FFF',
                    size: 12,
                    h: 40,                //(可选项) 数字类型；右边按钮的高度；默认：40
                    w: 60,                   //(可选项) 数字类型；右边按钮的宽度；默认：提示框的宽度的一半
                    marginB: 10,            //(可选项) 数字类型；右边按离底部的边距；默认：0
                    corner: 5,              //(可选项) 数字类型；右边按钮的圆角；默认：0
                    widhtBorder: 1,         //(可选项) 数字类型；右边按钮的边宽；默认：0
                    normalBorderColor: '#778899', //(可选项) 数字类型；右边按钮的边宽颜色；默认：'rgba(0,0,0,0)'
                    activeBorderColor: '#0000CD', //(可选项) 数字类型；右边按钮的高亮状态下边宽颜色；默认：'rgba(0,0,0,0)'
                    activeColor: '#006400', //(可选项) 数字类型；右边按钮的高亮状态下标题颜色；默认：'rgba(0,0,0,0)'
                    activeBg: '#6B8E23'   //(可选项) 数字类型；右边按钮的高亮状态下背景颜色；默认：'rgba(0,0,0,0)'
                }
            }
        }, function (ret) {
            //工号
            var empNo = ret.text;

            //取消
            if (ret.eventType == 'left') {
                dialogBox.close({
                    dialogName: 'input'
                });

                //确定
            } else {

                //卡号必输校验
                if (empNo == null || empNo == "" || empNo == undefined) {
                    api.toast({
                        msg: "请扫描/录入卡号!",
                        duration: 3000
                    });
                } else {
                    dialogBox.close({
                        dialogName: 'input'
                    });

                    //上岗离岗保存
                    save(flag, empNo);
                }
            }
        });
    }

    //上岗/离岗保存
    function save(flag, empNo) {
        var proddate = $("#prodDate").val();
        var teamCode = $("#teamCode").val();
        var shiftCode = $("#shiftCode").val();
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getAssemblyTakeQuitPostZSSave";
        var data = {
            values: {
                proddate: proddate,
                workCenterCode: api.pageParam.workCenterCode,
                workCellCode: api.pageParam.workCellCode,
                teamCode: teamCode,
                shiftCode: shiftCode,
                flag: flag,
                empNoStr: empNo,
                sgFlag: api.pageParam.sgFlag,//上岗标识：0刷卡，1勾选
                cjFlag: api.pageParam.cjFlag,//是否按工位上岗查询：0否，1是
                un: un
            }
        };

        var params = new Object();
        params.url = url;
        params.dataType = 'json';
        params.method = 'post';

        api.showProgress({
            title: '保存中...',
        });

        ajaxForData(params, data, false, function (ret, err) {
            if (ret) {
                api.hideProgress();
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");
                //成功
                if (myobj.code == 0) {
                    api.toast({
                        msg: "保存成功!",
                        duration: 3000
                    });

                    //上岗离岗记录信息
                    searchTakePostData();
                } else {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                api.hideProgress();
                alert("网络连接超时!")
            }
        });
    }

    //刷新按钮
    function refresh() {

        //获取设备唯一号
        equipUniqueId = localStorage.getItem('equipUniqueId');

        //上岗离岗记录信息
        searchTakePostData();

    }

    //返回按钮
    function closeWin() {
        api.closeToWin({ name: api.pageParam.rootName });
        api.execScript({
            name: api.pageParam.rootName,
            script: 'refresh()'
        });
    }
</script>

</html>